//package com.zmn.plat.task.job.price;
//
//import com.github.ltsopensource.core.domain.Action;
//import com.github.ltsopensource.core.domain.Job;
//import com.github.ltsopensource.spring.tasktracker.JobRunnerItem;
//import com.github.ltsopensource.spring.tasktracker.LTS;
//import com.github.ltsopensource.tasktracker.Result;
//import com.zmn.common.constant.GlobalConsts;
//import com.zmn.common.dictionary.DictModel;
//import com.zmn.common.dto.ResultDTO;
//import com.zmn.manager.lts.interfaces.task.TaskManager;
//import com.zmn.plat.business.interfaces.price.CommonBService;
//import com.zmn.plat.business.interfaces.price.MeterFlowBService;
//import com.zmn.plat.business.interfaces.price.meter3.MeterFlow3CommonBService;
//import com.zmn.plat.common.constant.ProductConsts;
//import com.zmn.plat.manager.dictionary.ProductDict;
//import com.zmn.plat.manager.utils.TaskConsts;
//import com.zmn.plat.model.entity.product.ServProduct;
//import com.zmn.plat.model.entity.product.ServProductQuery;
//import com.zmn.plat.services.interfaces.area.BaseAreaService;
//import com.zmn.plat.services.interfaces.product.ServProductService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import java.util.Arrays;
//import java.util.List;
//
///**
// * 描述: 产品价格任务
// *
// * @author guoqiao
// * @since 2021/9/23 18:42
// */
//@LTS
//public class PriceJob {
//    private Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Resource
//    TaskManager taskManager;
//    @Resource
//    CommonBService commonBService;
//    @Resource
//    ServProductService servProductService;
//    @Resource
//    BaseAreaService baseAreaService;
//    @Resource
//    MeterFlowBService meterFlowBService;
//    @Resource
//    MeterFlow3CommonBService meterFlow3CommonBService;
//    @Resource
//    RedisTemplate<String, String> redisTemplate;
//
//    // 计价器用到的渠道
//    private static final List<Integer> CITY_LIST = Arrays.asList(500100, 110100);
//    private static final List<Integer> CHANNEL_CHECK_LIST = Arrays.asList(32836);
//    private static final List<Integer> CHANNEL_LIST_LIST = Arrays.asList(40001, 40002, 40015, 41100,40014, 40009, 1402, 32836);
//    private static final List<Integer> TARIFF_TYPE_LIST = Arrays.asList(ProductDict.TRIFF_TYPE_SERVICE, ProductDict.TRIFF_TYPE_TARIFF, ProductDict.TRIFF_TYPE_ADVANCE, ProductDict.TRIFF_TYPE_TARIFF3);
//    private static final List<Integer> CHANNEL_LIST2 = Arrays.asList(40001,40002,40009,1402,32836);
//
//    @PostConstruct
//    void init() {
//
//        Job cityTariffJob = new Job();
//        cityTariffJob.setTaskId(TaskConsts.TASK_ID_CITY_TARIFF);
//        cityTariffJob.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_CITY_TARIFF);
//        cityTariffJob.setCronExpression("0 0/5 * * * ? *");
//        cityTariffJob.setReplaceOnExist(true);
//        ResultDTO cityTariffJobResult = taskManager.submitTask(cityTariffJob);
//        if (cityTariffJobResult.getStatusBool()) {
//            logger.info("提交城市支持计价器流程的数据成功......");
//        }
//
//        Job checkTariffJob = new Job();
//        checkTariffJob.setTaskId(TaskConsts.TASK_ID_CHECK_TARIFF);
//        checkTariffJob.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_CHECK_TARIFF);
//        checkTariffJob.setCronExpression("0 0/10 * * * ? *");
//        checkTariffJob.setReplaceOnExist(true);
//        ResultDTO checkTariffResult = taskManager.submitTask(checkTariffJob);
//        if (checkTariffResult.getStatusBool()) {
//            logger.info("提交校验是否支持计价器成功......");
//        }
//
//        Job listTariffJob = new Job();
//        listTariffJob.setTaskId(TaskConsts.TASK_ID_LIST_TARIFF);
//        listTariffJob.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_LIST_TARIFF);
//        listTariffJob.setCronExpression("0 0/10 * * * ? *");
//        listTariffJob.setReplaceOnExist(true);
//        ResultDTO listTariffResult = taskManager.submitTask(listTariffJob);
//        if (listTariffResult.getStatusBool()) {
//            logger.info("提交查询价格表成功......");
//        }
//
////        Job productTariffTypeJob = new Job();
////        productTariffTypeJob.setTaskId(TaskConsts.TASK_ID_TARIFF_TYPE);
////        productTariffTypeJob.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_TARIFF_TYPE);
////        productTariffTypeJob.setCronExpression("0 0/5 * * * ? *");
////        productTariffTypeJob.setReplaceOnExist(true);
////        ResultDTO productTariffTypeResult = taskManager.submitTask(productTariffTypeJob);
////        if (productTariffTypeResult.getStatusBool()) {
////            logger.info("提交查询价格表类型成功......");
////        }
//    }
//
//    /**
//     * 描述: 城市支持计价器流程的数据
//     *
//     * @author guoqiao
//     * @since 2021/9/23 18:46
//     */
//    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_CITY_TARIFF)
//    public Result runcityTariffJob(Job job) {
//        try {
//            logger.info("城市支持计价器流程的数据任务执行开始了");
//            // 查询城市
//            List<DictModel> cityList = baseAreaService.listAllCity();
//
//            for (Integer channelId : CHANNEL_CHECK_LIST) {
//                for (DictModel model : cityList) {
//                    String key = String.format("plat:redis5m:price:listServProductForTariff:channel:%s:city:%s:bizType:%s:categId:%s:categName:%s", channelId, model.getKey(), ProductConsts.BIZ_TYPE_C, null, null);
//                    redisTemplate.delete(key);
//                    meterFlowBService.listServProductForTariff(channelId, model.getKey(), ProductConsts.BIZ_TYPE_C, null, null);
//                }
//            }
//            logger.info("城市支持计价器流程的数据任务执行成功了");
//            return new Result(Action.EXECUTE_SUCCESS, "城市支持计价器流程的数据任务执行成功了!");
//        } catch (Exception e) {
//            logger.error("城市支持计价器流程的数据任务执行失败了,MSG:{}", e.getMessage(), e);
//            return new Result(Action.EXECUTE_FAILED, "城市支持计价器流程的数据任务执行失败了");
//        }
//    }
//
//    /**
//     * 描述: 校验是否支持计价器
//     *
//     * @author guoqiao
//     * @since 2021/9/23 18:46
//     */
//    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_CHECK_TARIFF)
//    public Result runCheckTariffJob(Job job) {
//        try {
//            logger.info("校验是否支持计价器任务执行开始了");
//            // 查询计价器产品对应的品类
//            ServProductQuery query = new ServProductQuery();
//            query.setShowType(ProductConsts.ET_PRODUCT_TYPE);
//            query.setStatus(GlobalConsts.YES);
//            List<ServProduct> servProducts = servProductService.listByQuery(query);
//            for (Integer channelId : CHANNEL_CHECK_LIST) {
//                for (ServProduct servProduct : servProducts) {
//                    String key = String.format("plat:redis1h:price:checkTariff:channelId:%s:productId:%s:showType:%s:bizType:%s", channelId, servProduct.getProductId(), ProductConsts.ET_PRODUCT_TYPE, ProductConsts.BIZ_TYPE_C);
//                    redisTemplate.delete(key);
//                    commonBService.checkTariff(channelId, servProduct.getProductId(), ProductConsts.ET_PRODUCT_TYPE, ProductConsts.BIZ_TYPE_C);
//                }
//            }
//            logger.info("校验是否支持计价器任务执行成功了");
//            return new Result(Action.EXECUTE_SUCCESS, "校验是否支持计价器任务执行成功了!");
//        } catch (Exception e) {
//            logger.error("校验是否支持计价器任务执行失败了,MSG:{}", e.getMessage(), e);
//            return new Result(Action.EXECUTE_FAILED, "校验是否支持计价器任务执行失败了");
//        }
//    }
//
//    /**
//     * 描述: 查询价格表
//     *
//     * @author guoqiao
//     * @since 2021/9/23 18:46
//     */
//    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_LIST_TARIFF)
//    public Result runListTariffJob(Job job) {
//        try {
//            logger.info("查询价格表任务执行开始了");
//            // 查询后产品对应的品类
//            ServProductQuery query = new ServProductQuery();
//            query.setShowType(ProductConsts.ERP_PRODUCT_TYPE);
//            query.setStatus(GlobalConsts.YES);
//            List<ServProduct> servProducts = servProductService.listByQuery(query);
//            for (Integer tariffType : TARIFF_TYPE_LIST) {
//                for (Integer channelId : CHANNEL_LIST_LIST) {
//                    for (ServProduct servProduct : servProducts) {
//                        String key = String.format("plat:redis1h:price:getTariff:channelId:%s:productIdList:%s:showType:%s:bizType:%s:tariffType:%s", channelId, servProduct.getProductId(), ProductConsts.ERP_PRODUCT_TYPE, ProductConsts.BIZ_TYPE_C, tariffType);
//                        redisTemplate.delete(key);
//                        commonBService.getTariff(channelId, Arrays.asList(servProduct.getProductId()), ProductConsts.ERP_PRODUCT_TYPE, ProductConsts.BIZ_TYPE_C, tariffType);
//                    }
//                }
//            }
//            logger.info("查询价格表任务执行成功了");
//            return new Result(Action.EXECUTE_SUCCESS, "查询价格表任务执行成功了!");
//        } catch (Exception e) {
//            logger.error("查询价格表任务执行失败了,MSG:{}", e.getMessage(), e);
//            return new Result(Action.EXECUTE_FAILED, "查询价格表任务执行失败了");
//        }
//    }
//
//    /**
//     * 描述: 通过渠道、后台产品、价格表类型获取支持的价格表信息
//     *
//     * @author guoqiao
//     * @since 2021/12/01 18:46
//     */
//    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_TARIFF_TYPE)
//    public Result runProductTariffTypeJob(Job job) {
//        try {
//            logger.info("查询价格表类型任务执行开始了");
//            // 查询后产品对应的品类
//            ServProductQuery query = new ServProductQuery();
//            query.setShowType(ProductConsts.ERP_PRODUCT_TYPE);
//            query.setStatus(GlobalConsts.YES);
//            List<ServProduct> erpProductList = servProductService.listByQuery(query);
//
//            for (Integer tariffType : TARIFF_TYPE_LIST) {
//                for (Integer channelId : CHANNEL_LIST2) {
//                    for (ServProduct erpProduct : erpProductList) {
//                        String key = String.format("plat:redis5m:price3:getProductTariffType:channelId:%s:productId:%s:bizType:%s:tariffType:%s", channelId, erpProduct.getProductId(), ProductConsts.BIZ_TYPE_C, tariffType);
//                        redisTemplate.delete(key);
//                        meterFlow3CommonBService.getProductTariffType(channelId, erpProduct.getProductId(), ProductConsts.BIZ_TYPE_C, tariffType);
//                    }
//                }
//            }
//            logger.info("查询价格表类型任务执行成功了");
//            return new Result(Action.EXECUTE_SUCCESS, "查询价格表类型任务执行成功了!");
//        } catch (Exception e) {
//            logger.error("查询价格表类型任务执行失败了,MSG:{}", e.getMessage(), e);
//            return new Result(Action.EXECUTE_FAILED, "查询价格表类型任务执行失败了");
//        }
//    }
//}
